package com.kai;

import com.kai.dao.EmpDao;
import com.kai.dao.impl.EmpDaoImpl;
import com.kai.pojo.Emp;
import org.junit.Test;

import java.io.IOException;
import java.util.List;

/**
 * Created By ShaoXikai on 2022/5/21
 */
public class ContextTest {

    private final EmpDao empDao = new EmpDaoImpl();

    // 添加
    @Test
    public void testAddEmp() {
        int i = empDao.addEmp(new Emp(12L, "马飞", "飞行员", 655565665));
        if (i == 1) {
            System.out.println("OK");
            System.out.println(empDao.selectById(12L));
        } else {
            System.out.println("NO");
        }
    }

    // 根据id删除
    @Test
    public void testDeleteById() {
        int i = empDao.deleteById(12L);
        if (i == 1) {
            System.out.println("OK");
            empDao.selectList().forEach(System.out::println);
        } else {
            System.out.println("NO");
        }
    }

    // 根据id更新信息
    @Test
    public void testUpdate() {
        Emp emp = new Emp();
        emp.setId(12L);
        emp.setJob("捡垃圾");
        emp.setName("搞飞机");
        int i = empDao.updateById(emp);
        if (i == 1) {
            System.out.println("OK");
            System.out.println(empDao.selectById(12L));
        } else {
            System.out.println("NO");
        }
    }

    // 查询所有
    @Test
    public void testSelectList() {
        List<Emp> emps = empDao.selectList();
        emps.forEach(System.out::println);

    }

    // 根据id查询
    @Test
    public void testSelectById() {
        Emp emp = empDao.selectById(5L);
        System.out.println(emp);
    }
}
